package cn.stylefeng.guns.modular.info.service;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.modular.info.entity.Game;
import cn.stylefeng.guns.modular.info.entity.Team;
import cn.stylefeng.guns.modular.info.mapper.TeamMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.swagger.models.auth.In;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: guns-vip
 * @description:
 * @author: xiesm
 * @create: 2019-12-30 17:57
 **/
@Service
public class TeamService extends ServiceImpl<TeamMapper, Team> {

    public List<Team> findTeamList() {
        QueryWrapper<Team> queryWrapper = new QueryWrapper<>();
        queryWrapper.gt("id", 0);
        return this.baseMapper.selectList(queryWrapper);
    }

    public Map<Integer, String> findTeamMap() {
        List<Team> teams = findTeamList();
        Map<Integer, String> teamMap = new HashMap<>();
        teams.forEach(team -> teamMap.put(team.getId(), team.getName()));
        return teamMap;
    }

    public Integer[] findTeamIdByName(String name) {
        QueryWrapper<Team> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("name", name);
        List<Team> teams = baseMapper.selectList(queryWrapper);
        List<Integer> ids = new ArrayList<>();
        Integer[] arrs = new Integer[teams.size()];
        teams.forEach(team -> ids.add(team.getId()));
        return ids.toArray(arrs);
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }
}
